package jinyilw.swing.rlaf.ui;

import jinyilw.common.JvmTools;
import jinyilw.common.OSTools;
import jinyilw.common.log.LogTools;
import jinyilw.swing.FontTools;
import jinyilw.swing.NativeTools;
import jinyilw.swing.rlaf.ui.icon.RIconFactory;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileChooserDetailsViewIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileChooserHomeFolderIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileChooserListViewIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileChooserNewFolderIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileChooserUpFolderIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileViewComputerIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileViewDirectoryIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileViewFileIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileViewFloppyDriveIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RFileViewHardDriveIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.ROptionPaneErrorIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.ROptionPaneInformationIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.ROptionPaneQuestionIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.ROptionPaneWarningIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RTreeClosedIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RTreeCollapsedIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RTreeExpandedIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RTreeLeafIcon;
import jinyilw.swing.rlaf.ui.icon.RIconFactory.RTreeOpenIcon;
import jinyilw.swing.rlaf.ui.icon.RMenuArrowIcon;
import jinyilw.swing.rlaf.ui.icon.RadioButtonMenuItemIcon;
import jinyilw.swing.rlaf.utils.RBorderFactory;
import jinyilw.swing.rlaf.utils.RBorderFactory.EmptyBorder;
import jinyilw.swing.rlaf.utils.RBorderFactory.SimpleRoundBorder;
import jinyilw.swing.rlaf.utils.RPopupFactory;

import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.PopupFactory;
import javax.swing.UIDefaults;
import javax.swing.UIDefaults.LazyValue;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.text.DefaultEditorKit;
import java.awt.Insets;

/**
 * @author Jinyi
 */
public class RLookAndFeel extends BasicLookAndFeel
{
	private static final long serialVersionUID = 5000655220164535272L;
	private static boolean aquaLoaded;
	private static final Border TWO_BORDER = new EmptyBorder(2, 2, 2, 2);
	private static final Border MENU_BORDER = new EmptyBorder(4, 0, 4, 0);
	private final boolean isMacAppMenuBarEnabled = NativeTools.isMacAppMenuBarEnabled();

	public RLookAndFeel()
	{
		LogTools.info("初始化RLookAndFeel主题包");
	}

	@Override
	public UIDefaults getDefaults()
	{
		UIDefaults uiDefaults = super.getDefaults();

		uiDefaults.put("CheckBox.icon",
				(LazyValue) t -> RIconFactory.getCheckIcon());
		uiDefaults.put("RadioButton.icon",
				(LazyValue) t -> RIconFactory.getRadioIcon());
		uiDefaults.put("CheckBoxMenuItem.checkIcon",
				(LazyValue) t -> RIconFactory.getCheckIcon());
		uiDefaults.put("RadioButtonMenuItem.checkIcon",
				(LazyValue) t -> new RadioButtonMenuItemIcon());
		uiDefaults.put("InternalFrame.icon", (LazyValue) t -> RIconFactory
				.getScaleIcon("internalFrame.png"));

		uiDefaults.put("FileChooser.detailsViewIcon",
				(LazyValue) t -> new RFileChooserDetailsViewIcon());
		uiDefaults.put("FileChooser.homeFolderIcon",
				(LazyValue) t -> new RFileChooserHomeFolderIcon());
		uiDefaults.put("FileChooser.listViewIcon",
				(LazyValue) t -> new RFileChooserListViewIcon());
		uiDefaults.put("FileChooser.newFolderIcon",
				(LazyValue) t -> new RFileChooserNewFolderIcon());
		uiDefaults.put("FileChooser.upFolderIcon",
				(LazyValue) t -> new RFileChooserUpFolderIcon());

		uiDefaults.put("FileView.computerIcon",
				(LazyValue) t -> new RFileViewComputerIcon());
		uiDefaults.put("FileView.directoryIcon",
				(LazyValue) t -> new RFileViewDirectoryIcon());
		uiDefaults.put("FileView.fileIcon",
				(LazyValue) t -> new RFileViewFileIcon());
		uiDefaults.put("FileView.hardDriveIcon",
				(LazyValue) t -> new RFileViewHardDriveIcon());
		uiDefaults.put("FileView.floppyDriveIcon",
				(LazyValue) t -> new RFileViewFloppyDriveIcon());

		uiDefaults.put("Tree.openIcon", (LazyValue) t -> new RTreeOpenIcon());
		uiDefaults.put("Tree.closedIcon",
				(LazyValue) t -> new RTreeClosedIcon());
		uiDefaults.put("Tree.leafIcon", (LazyValue) t -> new RTreeLeafIcon());
		uiDefaults.put("Tree.expandedIcon",
				(LazyValue) t -> new RTreeExpandedIcon());
		uiDefaults.put("Tree.collapsedIcon",
				(LazyValue) t -> new RTreeCollapsedIcon());

		uiDefaults.put("OptionPane.questionIcon",
				(LazyValue) t -> new ROptionPaneQuestionIcon());
		uiDefaults.put("OptionPane.informationIcon",
				(LazyValue) t -> new ROptionPaneInformationIcon());
		uiDefaults.put("OptionPane.warningIcon",
				(LazyValue) t -> new ROptionPaneWarningIcon());
		uiDefaults.put("OptionPane.errorIcon",
				(LazyValue) t -> new ROptionPaneErrorIcon());

		uiDefaults.put("List.focusSelectedCellHighlightBorder",
				(LazyValue) t -> new SimpleRoundBorder(true, 8));
		uiDefaults.put("List.focusCellHighlightBorder",
				(LazyValue) t -> new SimpleRoundBorder(true, 8));
		uiDefaults.put("Table.scrollPaneCornerComponent", null);
		uiDefaults.put("Spinner.editorBorderPainted", Boolean.TRUE);

		uiDefaults.put("ComboBox.padding", new Insets(3, 3, 3, 0));
		uiDefaults.put("ComboBox.border", null);
		uiDefaults.put("MenuItem.border", MENU_BORDER);
		uiDefaults.put("Menu.border", MENU_BORDER);
		uiDefaults.put("MenuBar.border", TWO_BORDER);
		uiDefaults.put("Menu.arrowIcon", (LazyValue) t -> new RMenuArrowIcon());
		uiDefaults.put("ToolBar.border", TWO_BORDER);
		uiDefaults.put("ToolTip.border",
				(LazyValue) t -> new SimpleRoundBorder(3));
		uiDefaults.put("SplitPane.border", null);
		uiDefaults.put("SplitPaneDivider.border", null);

		// uiDefaults.put("ProgressBar.repaintInterval", 80);

		uiDefaults.put("TitledBorder.border",
				(LazyValue) t -> RBorderFactory.getDefaultBorder());
		uiDefaults.put("TitledBorder.font", FontTools.defaultFont);
		uiDefaults.put("TitledBorder.position", TitledBorder.ABOVE_TOP);

		return uiDefaults;
	}

	@Override
	public void initialize()
	{
		if (isMacAppMenuBarEnabled && JvmTools.getJavaRuntimeVersion() < 1.9)
			initializeAqua();
		super.initialize();
		PopupFactory.setSharedInstance(new RPopupFactory());
	}

	@Override
	protected void initClassDefaults(UIDefaults uiDefaults)
	{
		uiDefaults.put("SeparatorUI", "jinyilw.swing.rlaf.ui.RSeparatorUI");
		uiDefaults.put("PopupMenuSeparatorUI",
				"jinyilw.swing.rlaf.ui.RPopupMenuSeparatorUI");
		uiDefaults.put("ToolBarSeparatorUI",
				"jinyilw.swing.rlaf.ui.RToolBarSeparatorUI");
		uiDefaults.put("PanelUI", "jinyilw.swing.rlaf.ui.RPanelUI");
		uiDefaults.put("LabelUI", "jinyilw.swing.rlaf.ui.RLabelUI");
		uiDefaults.put("ButtonUI", "jinyilw.swing.rlaf.ui.RButtonUI");
		uiDefaults.put("ToggleButtonUI", "jinyilw.swing.rlaf.ui.RToggleButtonUI");
		uiDefaults.put("TextFieldUI", "jinyilw.swing.rlaf.ui.RTextFieldUI");
		uiDefaults.put("FormattedTextFieldUI",
				"jinyilw.swing.rlaf.ui.RFormattedTextFieldUI");
		uiDefaults.put("PasswordFieldUI", "jinyilw.swing.rlaf.ui.RPasswordFieldUI");
		uiDefaults.put("TextAreaUI", "jinyilw.swing.rlaf.ui.RTextAreaUI");
		uiDefaults.put("EditorPaneUI", "jinyilw.swing.rlaf.ui.REditorPaneUI");
		uiDefaults.put("TextPaneUI", "jinyilw.swing.rlaf.ui.RTextPaneUI");
		uiDefaults.put("RadioButtonUI", "jinyilw.swing.rlaf.ui.RRadioButtonUI");
		uiDefaults.put("CheckBoxUI", "jinyilw.swing.rlaf.ui.RCheckBoxUI");
		uiDefaults.put("ComboBoxUI", "jinyilw.swing.rlaf.ui.RComboBoxUI");
		uiDefaults.put("SpinnerUI", "jinyilw.swing.rlaf.ui.RSpinnerUI");
		uiDefaults.put("FileChooserUI", "jinyilw.swing.rlaf.ui.RFileChooserUI");
		uiDefaults.put("ColorChooserUI", "jinyilw.swing.rlaf.ui.RColorChooserUI");
		uiDefaults.put("ListUI", "jinyilw.swing.rlaf.ui.RListUI");
		uiDefaults.put("TreeUI", "jinyilw.swing.rlaf.ui.RTreeUI");
		uiDefaults.put("TableUI", "jinyilw.swing.rlaf.ui.RTableUI");
		uiDefaults.put("TableHeaderUI", "jinyilw.swing.rlaf.ui.RTableHeaderUI");
		uiDefaults.put("MenuItemUI", "jinyilw.swing.rlaf.ui.RMenuItemUI");
		uiDefaults.put("CheckBoxMenuItemUI",
				"jinyilw.swing.rlaf.ui.RCheckBoxMenuItemUI");
		uiDefaults.put("RadioButtonMenuItemUI",
				"jinyilw.swing.rlaf.ui.RRadioButtonMenuItemUI");
		uiDefaults.put("MenuUI", "jinyilw.swing.rlaf.ui.RMenuUI");
		uiDefaults.put("MenuBarUI", "jinyilw.swing.rlaf.ui.RMenuBarUI");
		uiDefaults.put("ToolBarUI", "jinyilw.swing.rlaf.ui.RToolBarUI");
		uiDefaults.put("ToolTipUI", "jinyilw.swing.rlaf.ui.RToolTipUI");
		uiDefaults.put("PopupMenuUI", "jinyilw.swing.rlaf.ui.RPopupMenuUI");
		uiDefaults.put("TabbedPaneUI", "jinyilw.swing.rlaf.ui.RTabbedPaneUI");
		uiDefaults.put("ScrollPaneUI", "jinyilw.swing.rlaf.ui.RScrollPaneUI");
		uiDefaults.put("ScrollBarUI", "jinyilw.swing.rlaf.ui.RScrollBarUI");
		uiDefaults.put("ViewportUI", "jinyilw.swing.rlaf.ui.RViewportUI");
		uiDefaults.put("RootPaneUI", "jinyilw.swing.rlaf.ui.RRootPaneUI");
		uiDefaults.put("OptionPaneUI", "jinyilw.swing.rlaf.ui.ROptionPaneUI");
		uiDefaults.put("SplitPaneUI", "jinyilw.swing.rlaf.ui.RSplitPaneUI");
		uiDefaults.put("InternalFrameUI", "jinyilw.swing.rlaf.ui.RInternalFrameUI");
		uiDefaults.put("DesktopPaneUI", "jinyilw.swing.rlaf.ui.RDesktopPaneUI");
		uiDefaults.put("DesktopIconUI", "jinyilw.swing.rlaf.ui.RDesktopIconUI");
		uiDefaults.put("SliderUI", "jinyilw.swing.rlaf.ui.RSliderUI");
		uiDefaults.put("ProgressBarUI", "jinyilw.swing.rlaf.ui.RProgressBarUI");

		if (isMacAppMenuBarEnabled)
		{
			uiDefaults.put("MenuBarUI", "com.apple.laf.AquaMenuBarUI");
			uiDefaults.put("MenuBar.backgroundPainter",
					BorderFactory.createEmptyBorder());
		}
	}

	@Override
	protected void initComponentDefaults(UIDefaults table)
	{
		super.initComponentDefaults(table);
		if (OSTools.isMac())
		{
			initMacInputMap(table);
		} else
		{
			initWindowsInputMap(table);
		}
	}

	private void initMacInputMap(UIDefaults table)
	{
		AquaKeyBindings aquaKeyBindings = AquaKeyBindings.getAquaKeyBindings();
		Object fieldInputMap = aquaKeyBindings.getTextFieldInputMap();
		Object passwordInputMap = aquaKeyBindings.getPasswordFieldInputMap();
		Object multilineInputMap = aquaKeyBindings.getMultiLineTextInputMap();
		table.put("TextField.focusInputMap", fieldInputMap);
		table.put("PasswordField.focusInputMap", passwordInputMap);
		table.put("TextArea.focusInputMap", multilineInputMap);
		table.put("TextPane.focusInputMap", multilineInputMap);
		table.put("EditorPane.focusInputMap", multilineInputMap);

		table.put("FormattedTextField.focusInputMap",
				aquaKeyBindings.getFormattedTextFieldInputMap());
		table.put("ComboBox.ancestorInputMap",
				aquaKeyBindings.getComboBoxInputMap());
		table.put("List.focusInputMap", aquaKeyBindings.getListInputMap());
		table.put("ScrollBar.focusInputMap",
				aquaKeyBindings.getScrollBarInputMap());
		table.put("ScrollBar.focusInputMap.RightToLeft",
				aquaKeyBindings.getScrollBarRightToLeftInputMap());
		table.put("ScrollPane.ancestorInputMap",
				aquaKeyBindings.getScrollPaneInputMap());
		table.put("ScrollPane.ancestorInputMap.RightToLeft",
				new UIDefaults.LazyInputMap(new Object[]{}));
		table.put("Table.ancestorInputMap", aquaKeyBindings.getTableInputMap());
		table.put("Table.ancestorInputMap.RightToLeft",
				aquaKeyBindings.getTableRightToLeftInputMap());
		table.put("Tree.focusInputMap", aquaKeyBindings.getTreeInputMap());
		table.put("Tree.focusInputMap.RightToLeft",
				aquaKeyBindings.getTreeRightToLeftInputMap());
	}

	private void initWindowsInputMap(UIDefaults table)
	{
		Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[]{
				"control C", DefaultEditorKit.copyAction, "control V",
				DefaultEditorKit.pasteAction, "control X",
				DefaultEditorKit.cutAction, "COPY", DefaultEditorKit.copyAction,
				"PASTE", DefaultEditorKit.pasteAction, "CUT",
				DefaultEditorKit.cutAction, "control INSERT",
				DefaultEditorKit.copyAction, "shift INSERT",
				DefaultEditorKit.pasteAction, "shift DELETE",
				DefaultEditorKit.cutAction, "control A",
				DefaultEditorKit.selectAllAction, "control BACK_SLASH",
				"unselect", "shift LEFT",
				DefaultEditorKit.selectionBackwardAction, "shift RIGHT",
				DefaultEditorKit.selectionForwardAction, "control LEFT",
				DefaultEditorKit.previousWordAction, "control RIGHT",
				DefaultEditorKit.nextWordAction, "control shift LEFT",
				DefaultEditorKit.selectionPreviousWordAction,
				"control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
				"HOME", DefaultEditorKit.beginLineAction, "END",
				DefaultEditorKit.endLineAction, "shift HOME",
				DefaultEditorKit.selectionBeginLineAction, "shift END",
				DefaultEditorKit.selectionEndLineAction, "BACK_SPACE",
				DefaultEditorKit.deletePrevCharAction, "shift BACK_SPACE",
				DefaultEditorKit.deletePrevCharAction, "ctrl H",
				DefaultEditorKit.deletePrevCharAction, "DELETE",
				DefaultEditorKit.deleteNextCharAction, "ctrl DELETE",
				DefaultEditorKit.deleteNextWordAction, "ctrl BACK_SPACE",
				DefaultEditorKit.deletePrevWordAction, "RIGHT",
				DefaultEditorKit.forwardAction, "LEFT",
				DefaultEditorKit.backwardAction, "KP_RIGHT",
				DefaultEditorKit.forwardAction, "KP_LEFT",
				DefaultEditorKit.backwardAction, "ENTER",
				JTextField.notifyAction, "control shift O",
				"toggle-componentOrientation"});

		Object passwordInputMap = new UIDefaults.LazyInputMap(new Object[]{
				"control C", DefaultEditorKit.copyAction, "control V",
				DefaultEditorKit.pasteAction, "control X",
				DefaultEditorKit.cutAction, "COPY", DefaultEditorKit.copyAction,
				"PASTE", DefaultEditorKit.pasteAction, "CUT",
				DefaultEditorKit.cutAction, "control INSERT",
				DefaultEditorKit.copyAction, "shift INSERT",
				DefaultEditorKit.pasteAction, "shift DELETE",
				DefaultEditorKit.cutAction, "control A",
				DefaultEditorKit.selectAllAction, "control BACK_SLASH",
				"unselect", "shift LEFT",
				DefaultEditorKit.selectionBackwardAction, "shift RIGHT",
				DefaultEditorKit.selectionForwardAction, "control LEFT",
				DefaultEditorKit.beginLineAction, "control RIGHT",
				DefaultEditorKit.endLineAction, "control shift LEFT",
				DefaultEditorKit.selectionBeginLineAction,
				"control shift RIGHT", DefaultEditorKit.selectionEndLineAction,
				"HOME", DefaultEditorKit.beginLineAction, "END",
				DefaultEditorKit.endLineAction, "shift HOME",
				DefaultEditorKit.selectionBeginLineAction, "shift END",
				DefaultEditorKit.selectionEndLineAction, "BACK_SPACE",
				DefaultEditorKit.deletePrevCharAction, "shift BACK_SPACE",
				DefaultEditorKit.deletePrevCharAction, "ctrl H",
				DefaultEditorKit.deletePrevCharAction, "DELETE",
				DefaultEditorKit.deleteNextCharAction, "RIGHT",
				DefaultEditorKit.forwardAction, "LEFT",
				DefaultEditorKit.backwardAction, "KP_RIGHT",
				DefaultEditorKit.forwardAction, "KP_LEFT",
				DefaultEditorKit.backwardAction, "ENTER",
				JTextField.notifyAction, "control shift O",
				"toggle-componentOrientation"});

		Object multilineInputMap = new UIDefaults.LazyInputMap(new Object[]{
				"control C", DefaultEditorKit.copyAction, "control V",
				DefaultEditorKit.pasteAction, "control X",
				DefaultEditorKit.cutAction, "COPY", DefaultEditorKit.copyAction,
				"PASTE", DefaultEditorKit.pasteAction, "CUT",
				DefaultEditorKit.cutAction, "control INSERT",
				DefaultEditorKit.copyAction, "shift INSERT",
				DefaultEditorKit.pasteAction, "shift DELETE",
				DefaultEditorKit.cutAction, "shift LEFT",
				DefaultEditorKit.selectionBackwardAction, "shift RIGHT",
				DefaultEditorKit.selectionForwardAction, "control LEFT",
				DefaultEditorKit.previousWordAction, "control RIGHT",
				DefaultEditorKit.nextWordAction, "control shift LEFT",
				DefaultEditorKit.selectionPreviousWordAction,
				"control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
				"control A", DefaultEditorKit.selectAllAction,
				"control BACK_SLASH", "unselect", "HOME",
				DefaultEditorKit.beginLineAction, "END",
				DefaultEditorKit.endLineAction, "shift HOME",
				DefaultEditorKit.selectionBeginLineAction, "shift END",
				DefaultEditorKit.selectionEndLineAction, "control HOME",
				DefaultEditorKit.beginAction, "control END",
				DefaultEditorKit.endAction, "control shift HOME",
				DefaultEditorKit.selectionBeginAction, "control shift END",
				DefaultEditorKit.selectionEndAction, "UP",
				DefaultEditorKit.upAction, "DOWN", DefaultEditorKit.downAction,
				"BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
				"shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
				"ctrl H", DefaultEditorKit.deletePrevCharAction, "DELETE",
				DefaultEditorKit.deleteNextCharAction, "ctrl DELETE",
				DefaultEditorKit.deleteNextWordAction, "ctrl BACK_SPACE",
				DefaultEditorKit.deletePrevWordAction, "RIGHT",
				DefaultEditorKit.forwardAction, "LEFT",
				DefaultEditorKit.backwardAction, "KP_RIGHT",
				DefaultEditorKit.forwardAction, "KP_LEFT",
				DefaultEditorKit.backwardAction, "PAGE_UP",
				DefaultEditorKit.pageUpAction, "PAGE_DOWN",
				DefaultEditorKit.pageDownAction, "shift PAGE_UP",
				"selection-page-up", "shift PAGE_DOWN", "selection-page-down",
				"ctrl shift PAGE_UP", "selection-page-left",
				"ctrl shift PAGE_DOWN", "selection-page-right", "shift UP",
				DefaultEditorKit.selectionUpAction, "shift DOWN",
				DefaultEditorKit.selectionDownAction, "ENTER",
				DefaultEditorKit.insertBreakAction, "TAB",
				DefaultEditorKit.insertTabAction, "control T",
				"next-link-action", "control shift T", "previous-link-action",
				"control SPACE", "activate-link-action", "control shift O",
				"toggle-componentOrientation"});
		table.put("TextField.focusInputMap", fieldInputMap);
		table.put("PasswordField.focusInputMap", passwordInputMap);
		table.put("TextArea.focusInputMap", multilineInputMap);
		table.put("TextPane.focusInputMap", multilineInputMap);
		table.put("EditorPane.focusInputMap", multilineInputMap);

		table.put("ScrollBar.ancestorInputMap",
				new UIDefaults.LazyInputMap(new Object[]{"RIGHT",
						"positiveUnitIncrement", "KP_RIGHT",
						"positiveUnitIncrement", "DOWN",
						"positiveUnitIncrement", "KP_DOWN",
						"positiveUnitIncrement", "PAGE_DOWN",
						"positiveBlockIncrement", "ctrl PAGE_DOWN",
						"positiveBlockIncrement", "LEFT",
						"negativeUnitIncrement", "KP_LEFT",
						"negativeUnitIncrement", "UP", "negativeUnitIncrement",
						"KP_UP", "negativeUnitIncrement", "PAGE_UP",
						"negativeBlockIncrement", "ctrl PAGE_UP",
						"negativeBlockIncrement", "HOME", "minScroll", "END",
						"maxScroll"}));

		table.put("TabbedPane.ancestorInputMap",
				new UIDefaults.LazyInputMap(new Object[]{"ctrl TAB",
						"navigateNext", "ctrl shift TAB", "navigatePrevious",
						"ctrl PAGE_DOWN", "navigatePageDown", "ctrl PAGE_UP",
						"navigatePageUp", "ctrl UP", "requestFocus",
						"ctrl KP_UP", "requestFocus",}));
	}

	@Override
	public boolean getSupportsWindowDecorations()
	{
		return true;
	}

	@Override
	public String getName()
	{
		return "jinyilw.swing.rlaf.ui.RLookAndFeel";
	}

	@Override
	public String getID()
	{
		return null;
	}

	@Override
	public String getDescription()
	{
		return "RLookAndFeel";
	}

	@Override
	public boolean isNativeLookAndFeel()
	{
		return false;
	}

	@Override
	public boolean isSupportedLookAndFeel()
	{
		return true;
	}

	private void initializeAqua()
	{
		if (aquaLoaded)
			return;

		// System.out.println("initializeAqua");

		aquaLoaded = true;

		// create macOS Aqua LaF
		String aquaLafClassName = "com.apple.laf.AquaLookAndFeel";
		BasicLookAndFeel aquaLaf;
		try
		{
			aquaLaf = (BasicLookAndFeel) Class.forName(aquaLafClassName)
					.getDeclaredConstructor().newInstance();
		} catch (Exception ex)
		{
			return;
		}
		PopupFactory oldPopupFactory = PopupFactory.getSharedInstance();

		// initialize Aqua LaF
		aquaLaf.initialize();
		aquaLaf.uninitialize();

		// restore popup factory
		PopupFactory.setSharedInstance(oldPopupFactory);
	}
}
